package com.xiaotu.code.dao.blog;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.query.dsl.QueryBuilder;
import org.springframework.stereotype.Repository;

import com.xiaotu.code.dao.HibernateDao;
import com.xiaotu.code.model.blog.Blog;
import com.xiaotu.code.system.DaoException;

@Repository(value="blogDao")
public class BlogDao extends HibernateDao<Blog,Long>{
	
	@SuppressWarnings("unchecked")
	public List<Blog> queryList(String queryKey)throws DaoException{
	    Session session=super.getSession();
	    FullTextSession fullTextSession = Search.getFullTextSession(session);  
	    QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity( Blog.class ).get();  
	    org.apache.lucene.search.Query query =qb.keyword().onFields("title").matching(queryKey).createQuery();  
	    Query hibQuery = fullTextSession.createFullTextQuery(query, Blog.class);  
	    List result = hibQuery.list();  
	    
	    System.out.println("========================="+result.size()+"============================");
	    return result;
	}
}
